<h1>Role Manager</h1>
<?php echo form_open_multipart('', array('class' => 'form-horizontal well')); ?>
<fieldset>
    <legend><?php echo (isset($info)) ? 'Edit Role' : 'Add Role' ?></legend>
    <div class="control-group">
        <label class="control-label">Role Title</label>
        <div class="controls">
            <?php echo form_input($form['role_title']) ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">Role Name</label>
        <div class="controls">
            <?php echo form_input($form['role_name']) ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">Role Rule</label>
        <div class="controls">
            <?php $rule = isset($info) ? json_decode($info->role_rule, true) : array(); ?>
            <?php
            if (!empty($module)) : foreach ($module as $value) :
                    echo $value->module_name . '<br />';
                    $controller = json_decode($value->controller_action);
                    if (!empty($controller)) : foreach ($controller as $key => $actions) :
                            ?>
                            <div>
                                <?php echo '--' . $key . ':'; ?>
                                <?php foreach ($actions as $action) : ?>
                                    <label class="checkbox inline">
                                        <input type="checkbox" <?php echo (isset($rule[$value->module_name][$key][$action]) ? 'checked' : '') ?> name="role_rule[<?php echo $value->module_name ?>][<?php echo $key ?>][<?php echo $action ?>]" value="1"/> <?php echo $action ?>
                                    </label>
                                <?php endforeach; ?>
                            </div>
                            <?php
                        endforeach;
                    endif;
                    ?>
                    <?php
                endforeach;
            endif;
            ?>
        </div>
    </div>
    <div class="form-actions">
        <?php echo form_submit($form['submit']) ?>
    </div>
</fieldset>
</form>